<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/commons :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客发布</title>
<!--    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">-->
<!--    <link rel="stylesheet" th:href="@{/css/semantic.min.css}">-->
<!--    <link rel="stylesheet" th:href="@{/css/style.css}">-->
<!--    <link rel="stylesheet" th:href="@{/lib/editormd/css/editormd.min.css}">-->
</head>
<body>

    <!--头部导航开始-->
    <!--thymeleaf 片段替换-->
    <div th:replace="admin/commons :: header(1)"></div>
    <!--头部导航结束-->

    <!--二级导航-->
    <div class="ui attached pointing menu">
        <div class="ui container">
            <div class="right menu">
                <a th:href="@{/admin/blogs/input}" class="teal active item">发布</a>
                <a th:href="@{/admin/blogs}" class="item">列表</a>
            </div>
        </div>
    </div>

    <!--中间部分开始-->
    <div class="v-container-small v-padded-tb-big">
        <div class="ui container">
            <form id="blog-form" th:action="@{/admin/blogs}" th:object="${blog}" class="ui form" method="post">

                <!--隐藏域，该文字是否发布-->
                <input type="hidden" name="published">

                <!--修改时的id的隐藏域,从页面对象中取出-->
                <input type="hidden" name="id" th:value="*{id}">

                <div class="required field">

                    <div class="ui left labeled input">
                        <div class="ui selection compact teal basic dropdown label">
                            <input type="hidden" name="flag" th:value="*{flag} != null ? *{flag} : '原创'" value="原创">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div>
                        <input type="text" name="title" th:value="*{title}" placeholder="标题">
                    </div>

                </div>

                <div class="required field">
                    <div id="md-content" style="z-index: 1!important;">
                        <textarea name="content" th:text="*{content}" placeholder="博客内容" style="display: none"></textarea>
                    </div>
                </div>
                <div class="two fields">
                    <div class="required field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui fluid selection dropdown">
                                <input type="hidden" th:value="*{type} != null ? *{type.id}" name="type.id">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div th:each="type : ${types}" class="item" th:text="${type.name}" th:data-value="${type.id}" ></div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">标签</label>
                            <div class="ui tag fluid selection multiple search dropdown">
                                <input type="hidden" th:value="*{tagIds}" name="tagIds">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu">
                                    <div th:each="tag : ${tags}" class="item" th:text="${tag.name}" th:data-value="${tag.id}" ></div>
                                    <!--thymleaf模板引擎下隐藏下面的内容，html下显示-->
                                    <!--/*-->
                                    <div class="item" data-value="1">java</div>
                                    <div class="item" data-value="2">css</div>
                                    <!--*/-->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="required field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label>
                        <input type="text" th:value="*{firstPicture}" name="firstPicture" placeholder="首图引用地址">
                    </div>
                </div>

                <div class="required field">
                    <textarea name="description" th:text="*{description}" placeholder="博客描述..." maxlength="200"></textarea>
                </div>

                <div class="inline fields">
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="recommended" name="recommended" checked th:checked="*{recommended}" class="hidden">
                            <label for="recommended">推荐</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}" class="hidden">
                            <label for="shareStatement">转载声明</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="appreciation" name="appreciation" th:checked="*{appreciation}" class="hidden">
                            <label for="appreciation">赞赏</label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox">
                            <input type="checkbox" id="commentEnabled" name="commentEnabled" th:checked="*{commentEnabled}" class="hidden">
                            <label for="commentEnabled">评论</label>
                        </div>
                    </div>
                </div>

                <div class="ui error message"></div>

                <div class="ui right aligned container">
                    <button type="button" class="ui button" onclick="history.go(-1)">返回</button>
                    <button type="button" id="save-btn" class="ui secondary button">保存</button>
                    <button type="button" id="publish-btn" class="ui teal button">发布</button>
                </div>
            </form>

        </div>
    </div>
    <!--中间部分结束-->
    <br>
    <br>

    <!--底部部分开始-->
    <!--thymeleaf 片段替换-->
    <div th:replace="admin/commons :: #footer"></div>
    <!--底部部分结束-->



<!--<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>-->
<!--<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>-->
<!--<script th:src="@{/js/jquery-3.6.0.min.js}"></script>-->
<!--<script th:src="@{/js/semantic.min.js}"></script>-->
<!--<script th:src="@{/lib/editormd/editormd.min.js}"></script>-->

<!--/*/<th:block th:replace="admin/commons :: script">/*/-->
    <!--thymeleaf 引入js资源，这三行不为注释-->
<!--/*/</th:block>/*/-->
<script>
    //初始化markdown编辑器
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            path    : "/lib/editormd/lib/"
        });
    });

    $('.menu.toggle').click(function () {
        $('.v-item').toggleClass('v-mobile-hidden')
    });

    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    //定义标签栏可以自添加
    $('.tag.ui.dropdown')
        .dropdown({
            allowAdditions: true
        })
    ;

    //表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'title',
                rules: [{
                    type: 'empty',
                    prompt:'标题：请输入博客标题'
                }]
            },
            content: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt:'标题：请输入博客内容'
                }]
            },
            typeId: {
                identifier: 'typeId',
                rules: [{
                    type: 'empty',
                    prompt:'标题：请输入博客分类'
                }]
            },
            firstPicture: {
                identifier: 'firstPicture',
                rules: [{
                    type: 'empty',
                    prompt:'标题：请输入博客首图'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入博客描述'
                }]
            }
        }
    });

    //点击保存按钮将隐藏域置为false,发布按钮置为true
    $("#save-btn").click(function () {
        $("[name='published']").val(false);
        $("#blog-form").submit();
    });

    $("#publish-btn").click(function () {
        $("[name='published']").val(true);
        $("#blog-form").submit();
    });
</script>
</body>
</html>

